package com.leyou.item.controller;

import com.leyou.item.service.SpecService;
import com.ly.plus.dto.SpecGroupDTO;
import com.ly.plus.entity.SpecGroup;
import com.ly.plus.entity.SpecParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 规格数据控制层
 */
@RestController
public class SpecController {

    @Autowired
    private SpecService specService;

    /**
     * 根据分类id查询规格组列表
     * @param cid
     * @return
     */
    @GetMapping("/spec/groups/of/category")
    public ResponseEntity<List<SpecGroup>>findSpecGroupsByCid(@RequestParam("id")Long cid){
        List<SpecGroup>SpecGroupsList=specService.findSpecGroupsByCid(cid);
        return ResponseEntity.ok(SpecGroupsList);
    }

    /**
     * 查询规格参数
     * @param gid//规格组id
     * @param cid//分类id
     * @param searching//是否参与搜索
     * @return
     */
    @GetMapping("/spec/params")
    public ResponseEntity<List<SpecParam>>findSpecParams(@RequestParam(value = "gid",required = false)Long gid,
                                                         @RequestParam(value = "cid",required = false)Long cid,
                                                         @RequestParam(value = "searching",required = false)Boolean searching
                                                                                                                ){


      List<SpecParam>specParamList= specService.findSpecParams(gid,cid,searching);
        return ResponseEntity.ok(specParamList);
    }

    /**
     * 根据分类id查询规格组和组内参数
     * @param cid
     * @return
     */
    @GetMapping("/spec/of/category")
    public ResponseEntity<List<SpecGroupDTO>>findSpecGroupDTOsByCid(@RequestParam("id")Long cid){
        List<SpecGroupDTO>SpecGroupDTOs =specService.findSpecGroupDTOsByCid(cid);
        return ResponseEntity.ok(SpecGroupDTOs);
    }

}